import 'package:card_swiper/card_swiper.dart';
import 'package:flutter/widgets.dart';

import '../../resource/resources.dart';
import '../gt_image.dart';
import 'gt_widget_inner_banner.dart';

/// @Title   图片的banner（指示器在内部）
/// @Author: bryce
/// @CreateDate: 2023年08月31日15:03:39
class GTImageInnerBanner extends StatelessWidget {
  /// 宽/高比例
  final double aspectRatio;
  final List<String> images;

  /// 是否自动滚动
  final bool autoplay;

  /// 是否循环滚动
  final bool loop;

  /// 自动滚动时间间隔 (in millisecond).
  final int autoplayDelay;

  /// 页面切换事件
  final ValueChanged<int>? onIndexChanged;

  /// 点击事件
  final SwiperOnTap? onTap;

  /// 控制器
  final SwiperController? controller;

  /// 是否显示分页指示器（只有在不止一页时这个属性才生效，如果只有1条那么即使这个为true也是不显示的）
  final bool paginationVisible;

  ///默认true选中为黑色指示器，false选中为白色指示器
  final bool? isDarkColor;

  const GTImageInnerBanner(
      {super.key,
      required this.images,
      this.controller,
      this.onIndexChanged,
      this.onTap,
      this.autoplay = true,
      this.loop = true,
      this.paginationVisible = true,
      this.aspectRatio = 351 / 140,
      this.autoplayDelay = 3000,
      this.isDarkColor});

  @override
  Widget build(BuildContext context) {
    if (images.isEmpty) return Container();
    return GTWidgetInnerBanner(
        aspectRatio: aspectRatio,
        itemCount: images.length,
        controller: controller,
        onIndexChanged: onIndexChanged,
        onTap: onTap,
        autoplay: autoplay,
        autoplayDelay: autoplayDelay,
        loop: loop,
        paginationVisible: paginationVisible,
        isDark: isDarkColor,
        itemBuilder: (_, index) => GTImage(
              url: images[index],
              fit: BoxFit.cover,
              placeholderPath: Images.icBannerPlaceholder,
              errorPath: Images.icBannerError,
            ));
  }
}
